<layout name ="common" />
<div class="templatemo-content-widget no-padding">
	<div class="panel panel-default table-responsive">
		<table class="table table-striped table-bordered templatemo-user-table">
			<thead>
				<tr>
					<th colspan="6" style="font-size: 20px;">分类列表</th>
				</tr>
				<tr>
					<th style="text-align: center;"><a href="__ROOT__/Cate/cateManage/order/id" class="white-text templatemo-sort-by">ID <span class="caret"></span></a></th>
					<th style="text-align: center;"><a href="__ROOT__/Cate/cateManage/order/cate" class="white-text templatemo-sort-by">分类名称 <span class="caret"></span></a></th>
					<th style="text-align: center;"><a href="__ROOT__/Cate/cateManage/order/count(*) desc" class="white-text templatemo-sort-by">文章数量 <span class="caret"></span></a></th>
					<th style="text-align: center;">操作</th>
				</tr>
			</thead>
			<tbody style="text-align: center;">
			<foreach name='res' item='k'>
				<tr>
					<td>{$k.id}</td>
					<td>{$k.cate}</td>
					<td>
					<if condition='$k.cateid eq null'>
					没有文章
					<else />
					{$k.count(*)}
					</if>
					</td>
					<td>
						<if condition='$admininfo.is_admin eq 1'>
						<a href="javascript:void(0)" class="templatemo-is-btn" onclick="moveCate({$k.id},'{$k.cate}')">移动文章</a>
						<a href="javascript:void(0)" onclick="change({$k.id},'{$k.cate}')" class="templatemo-is-btn">编辑</a>
						<a href="javascript:void(0)" onclick="delCate({$k.id})" class="templatemo-is-btn">删除</a>
					</td>
					<else />
					<td>当前用户无法操作</td>
					</if>
				</tr>
			</foreach>
			</tbody>
		</table>
		<div class="pagination-wrap">
			{$page}
		</div>
	</div>
	<div class="panel panel-default table-responsive">
		<div class="panel-heading"><h2 class="text-uppercase">添加分类</h2></div>
		<div class="panel-body">
			<form action="__ROOT__/cate/addCate.html" class="templatemo-login-form" method="post">
				<div class="form-group">
					<label>新分类名称</label>
					<input type="text" class="form-control" placeholder="2-10位，字母或汉字" name="cate">
				</div>
				<div class="form-group">
					<button type="submit" class="templatemo-blue-button">Submit</button>
				</div>
			</form>
		</div>
	</div>
</div>
<div id="changeCate" style="display: none;">
	<div style="margin: 200px auto; width: 300px; height: 250px;background-color:#FFF;border: 2px solid #000;"  class="templatemo-content-widget white-bg col-1 text-center templatemo-position-relative">
		<a href="javascript:void(0)" id="hide"><i class="fa fa-times"></i></a>
		<h2 class="text-uppercase blue-text margin-bottom-5"><strong></strong></h2>
		<hr>
		<h2 class="text-uppercase blue-text margin-bottom-5">新分类名称</h2>
		<form method="post" action="__ROOT__/cate/editCate">
			<input type="hidden" name="id" value="">
			<div class="form-group">
				<input type="text" class="form-control" placeholder="2-10位，字母或汉字" name="cate">
			</div>
			<div class="form-group">
				<button type="submit" class="templatemo-blue-button">提交修改</button>
			</div>
		</form>
	</div>
</div>
<div id="moveCate" style="display: none;">
	<div style="margin: 200px auto; width: 300px; height: 250px;background-color:#FFF;border: 2px solid #000;"  class="templatemo-content-widget white-bg col-1 text-center templatemo-position-relative">
		<a href="javascript:void(0)" id="hide1"><i class="fa fa-times"></i></a>
		<h2 class="text-uppercase blue-text margin-bottom-5"><strong></strong></h2>
		<hr>
		<h2 class="text-uppercase blue-text margin-bottom-5">选择转移新分类</h2>
		<form method="post" action="__ROOT__/cate/moveCate">
			<input type="hidden" name="id" value="">
			<div class="form-group">
				<select class="form-control" name="newcateid">
				<foreach name='res' item='k'>
					<option value="{$k.id}">{$k.cate}</option>
				</foreach>
				</select>
			</div>
			<div class="form-group">
				<button type="submit" class="templatemo-blue-button">提交修改</button>
			</div>
		</form>
	</div>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		$("#leftMenu a[class='active']").removeClass("active");
		$('#leftMenu a:eq(2)').addClass("active");
	});
	function delCate(id){
		if(window.confirm("您确定要删除吗？")){
			window.location="__ROOT__/cate/delCate/id/"+id;
		}
	}
	function moveCate(id,cate) {
		document.getElementById('moveCate').style.cssText='text-align: center; position: fixed; z-index:10; top:0px; left:0px; width: 100%; height: 100%; display: block; background-color: rgba(255,255,255,0.5);';
		$('#moveCate form input:first').val(id);
		$('#moveCate h2:eq(0) strong').html('原文章所属分类：'+cate);
		$('#hide1').show();
	}
	$('#hide1').click(function () {
		$('#moveCate').hide();
	})
	function change(id,cate) {
		document.getElementById('changeCate').style.cssText='text-align: center; position: fixed; z-index:10; top:0px; left:0px; width: 100%; height: 100%; display: block; background-color: rgba(255,255,255,0.5);';
		$('#changeCate form input:first').val(id);
		$('#changeCate h2:eq(0) strong').html('原分类名称：'+cate);
		$('#hide').show();
	}
	$('#hide').click(function () {
		$('#changeCate').hide();
	})
</script>